﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Diploma.Models;
using DiplomaWeb.Models.Student;

namespace DiplomaWeb.Models.CompaniesAndLecturers
{
    public class StudentsPracticeViewModel
    {
        public List<StudentViewModel> Students { get; set; }

        public List<SelectListItem> Companies { get; set; }

        public int LevelId { get; set; }

        public string LevelName { get; set; }

        public void ToViewModel(IEnumerable<Diploma.Models.Student> students)
        {
            Students = students.Select(r => new StudentViewModel(r)).ToList();
            if(Students.Any())
            {
                LevelId = Students.First().LevelId;
                LevelName = Students.First().LevelName;

                Companies = new List<SelectListItem>
                                {
                                    new SelectListItem{ Text = "Empty", Value = String.Empty }
                                };
                Companies.AddRange(DataManager.Instance.CompaniesRepository.GetAllForLevel(LevelId).Select(r => new SelectListItem
                                                                                                             {
                                                                                                                 Value = r.Id.ToString(),
                                                                                                                 Text = r.DisplayName
                                                                                                             }));
            }
        }
    }
}